/**
 * Handles the class DBInvoiceTest.
 * 
 * Author: Group 3
 * Date: 07-04-2014 Version: 1.0
 */
package testlayer;

import static org.junit.Assert.*;

import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.sql.SQLException;




import modellayer.Invoice;




import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import dblayer.DBInvoice;
import dblayer.DBConnection;


public class DBInvoiceTest {
	
	private static DBInvoice testInvoiceDB = new DBInvoice();
	private static Invoice testInvoiceInsert = new Invoice();
	private static DBConnection testConnection = DBConnection.getInstance();
	
	
	@BeforeClass
	/**
	 * 
	 * @throws SQLException
	 * @throws UnsupportedEncodingException
	 * @throws FileNotFoundException
	 */
	public static void setUp() throws SQLException, UnsupportedEncodingException, FileNotFoundException
	{
		
		testConnection.resetDatabase();
		
		testInvoiceInsert.setAmount(1);
		testInvoiceInsert.setInvoiceID(1);
		testInvoiceInsert.setInvoiceNo(1);
		testInvoiceInsert.setPaymentDate("01-02-2015");	
	}
	
	@AfterClass
	public static void tearDown() throws SQLException, FileNotFoundException {
		
		testConnection.resetDatabase();
	}
	
	/**
	 * Tests if you can get all invoices
	 */
	@Test
	public void testGetInvoices() {
		assertNotNull(testInvoiceDB.getAllInvoices());
	}

	/**
	 * Tests if you can get a single invoice based on an invoiceID
	 * @throws SQLException
	 */
	@Test
	public void testSelectSingleInvoice() throws SQLException {
		assertNotNull(testInvoiceDB.selectSingleInvoice(1));
	}

	/**
	 * Tests if you can insert a product to the database
	 * @throws SQLException
	 */
	@Test
	public void testInsertProduct() throws SQLException {
		assertNotSame(-1, testInvoiceDB.insertInvoice(testInvoiceInsert));
	}

	/**
	 * Tests if you can update an invoice in the database
	 * @throws SQLException
	 */
	@Test
	public void testUpdateInvoice() throws SQLException {
		testInvoiceDB.selectSingleInvoice(1).setAmount(1);
		assertNotSame(-1, testInvoiceDB.updateInvoice(testInvoiceDB.selectSingleInvoice(1)));
	}

	/**
	 * Tests if you can delete an invoice in the database
	 * @throws SQLException
	 */
	@Test
	public void testDeleteInvoice() throws SQLException {
		
		assertNotSame(-1, testInvoiceDB.deleteInvoice(testInvoiceDB.selectSingleInvoice(1)));

}

}
